package com.hoo.servlet;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class StartSocket {
    public List<SSocket> clients = new ArrayList<SSocket>();  
    private boolean started = false;  
    private ServerSocket ss = null;  
    private SSocket c = null;  

    public StartSocket() {  
        try {
            ss = new ServerSocket(8888);  
            started = true;  
        } catch (IOException ioe) {  
            ioe.printStackTrace();  
        }  
    }  
  
    public void start() {  
        try {  
            Socket s = this.getSs().accept();  
            System.out.println("Here comes a client! ");  
            if (s != null) {  
            	this.clients.add(c);
                c = new SSocket(s, true);  
                new Thread(c).start();
                c = null;  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
  
    public boolean isStarted() {  
        return started;  
    }  
  
    public void setStarted(boolean started) {  
        this.started = started;  
    }  
  
    public ServerSocket getSs() {  
        return ss;  
    }  
  
    public void setSs(ServerSocket ss) {  
        this.ss = ss;  
    }  
  
    public List<SSocket> getClients() {  
        return clients;  
    }  
  
    public void setClients(List<SSocket> clients) {  
        this.clients = clients;  
    }  
}
